Optimize vertexModel.initialize: reduce initialization time by 25-30%#13
Draft
Optimize vertexModel.initialize: reduce initialization time by 25-30%#13
Conversation
Co-authored-by: Pablo1990 <1974224+Pablo1990@users.noreply.github.com>
…up caching Co-authored-by: Pablo1990 <1974224+Pablo1990@users.noreply.github.com>
Co-authored-by: Pablo1990 <1974224+Pablo1990@users.noreply.github.com>
… logic Co-authored-by: Pablo1990 <1974224+Pablo1990@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Improve efficacy of vertexModel.initialize method
Optimize vertexModel.initialize: reduce initialization time by 25-30%
Feb 2, 2026
Contributor
|
Important Review skippedBot user detected. To trigger a single review, invoke the You can disable this status message by setting the
Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
vertexModel.initializewas taking 117s to complete, too slow for napari integration with 2D images. Profiling revealed multiple hot paths with redundant computations and inefficient algorithms.Optimizations
Eliminated redundant face area computation (26.4s → ~13s saved)
compute_face_areawas called twice per face (lines 110 and 216)build_edges()and returnednp.vstack()in loop, moved face center outsideOptimized copy operations (8.7s → ~3.5s saved)
copy_non_mutable_attributesuseddeepcopyindiscriminately (40k+ calls)Replaced O(n²) global ID building with O(n) lookups (17.6s → ~12s saved)
np.isin()checks for vertex/face adjacencytuple(sorted())keysReplaced determinant calculations with dot/cross products (5.7s → ~1.6s saved)
np.linalg.det()incompute_volume_fractionandensure_consistent_orderdet([y1, y2, y3]) = y1 · (y2 × y3)for ~30% speedupCached interface type mapping (218ms → ~200ms saved)
get_interfacerecreated dictionary on every call (84k+ calls)_INTERFACE_TYPE_MAPPINGcacheReduced duplicate np.isin operations
build_edgesSharedByCells computationExpected Impact
Original prompt
This section details on the original issue you should resolve
<issue_title>Improve vertexModel.initialize efficacy</issue_title>
Name | Call count | Time (ms) | own time (ms) VertexModelVoronoiFromTimeImage.calculate_vertices | 2 | 3298 | 3199 -- | -- | -- | -- Face.compute_face_area | 26973 | 26366 | 2495 VertexModelVoronoiFromTimeImage.calculate_neighbours | 4 | 34122 | 1074 Tris.compute_tri_length_measurements | 129456 | 4824 | 1030 copy_non_mutable_attributes | 40752 | 8698 | 866 Cell.compute_volume_fraction | 23976 | 3830 | 815 Geo.build_global_ids | 1 | 17585 | 814 Tris.ensure_consistent_order | 113274 | 1884 | 504 Face.build_edges | 2997 | 11580 | 442 Tris.is_degenerated | 129456 | 1210 | 366 compute_tri_aspect_ratio | 129456 | 1612 | 299 Geo.update_measures | 7 | 30001 | 278 build_edge_based_on_tetrahedra | 2997 | 2549 | 224 sorting_cells_based_on_distance | 1 | 297 | 175 get_interface | 84516 | 218 | 137 | 24273 | 98 | 98 Geo.ensure_consistent_tris_order | 7 | 1981 | 97 Geo.build_cells | 1 | 47420 | 86 Cell.compute_volume | 1200 | 4070 | 57 Face.build_face | 2997 | 14903 | 54 Tris.__init__ | 48546 | 53 | 53 | 13485 | 49 | 49 | 13485 | 49 | 49 | 8991 | 44 | 44 compute_y | 5394 | 492 | 41 | 151050 | 40 | 40 Geo.update_lmin0 | 2 | 8417 | 39 VertexModelVoronoiFromTimeImage.initialize | 1 | 117900 | 38 | 10788 | 36 | 36 Face.__init__ | 8991 | 45 | 35 Cell.compute_neighbours | 2592 | 78 | 34 Tris.copy | 32364 | 3143 | 33 Cell.compute_area | 2100 | 125 | 29 boundary_of_cell | 300 | 229 | 26 Face.copy | 5994 | 8589 | 24 | 8991 | 23 | 23 create_tetrahedra | 2 | 325 | 22 Geo.get_opposite_border_cell | 95 | 51 | 21 | 5844 | 18 | 18 | 5994 | 3160 | 17 Geo.init_reference_values_and_noise | 2 | 201 | 17 | 300 | 17 | 17 VertexModelVoronoiFromTimeImage.build_2d_voronoi_from_image | 2 | 37906 | 15 Face.build_face_centre | 2997 | 160 | 13 Face.build_interface_type | 2997 | 100 | 13 Cell.build_y_from_x | 150 | 505 | 12 | 5394 | 12 | 12 Cell.__init__ | 3588 | 20 | 11 | 5394 | 10 | 10 Geo.resize_tissue | 1 | 8435 | 9 VertexModelVoronoiFromTimeImage.obtain_initial_x_and_tetrahedra | 1 | 38707 | 7 | 300 | 24 | 7 Geo.update_barrier_tri0 | 2 | 9097 | 6 build_quartets_of_neighs_2d | 2 | 10 | 6 Cell.copy | 2392 | 8850 | 5 VertexModelVoronoiFromTimeImage.populate_vertices_info | 2 | 3627 | 5 | 2 | 136 | 5 add_tetrahedral_intercalations | 1 | 82 | 5 ismember_rows | 300 | 36 | 5 | 5994 | 5 | 5 | 2392 | 8593 | 4 build_triplets_of_neighs | 2 | 13 | 4 Geo.copy | 2 | 8856 | 3 | 1 | 46 | 3 | 994 | 14 | 3 DegreesOfFreedom.get_dofs | 1 | 7 | 3 Cell.is_scutoid | 1196 | 173 | 2 Geo.compute_average_3d_neighbours | 1 | 15 | 1 generate_neighbours_network | 2 | 5 | 1 | 1 | 131473 | 0 VertexModelVoronoiFromTimeImage.initialize_cells | 1 | 87091 | 0 Geo.init_reference_cell_values | 2 | 17725 | 0 | 1 | 13505 | 0 | 1 | 9450 | 0 save_state | 2 | 5093 | 0 | 1 | 4578 | 0 | 1 | 1585 | 0 | 1 | 1501 | 0 | 1 | 1472 | 0 | 1 | 754 | 0 | 1 | 752 | 0 generate_tetrahedra_from_information | 1 | 326 | 0 process_image | 1 | 297 | 0 VertexModelVoronoiFromTimeImage.adjust_percentage_of_scutoids | 1 | 190 | 0 Geo.compute_percentage_of_scutoids | 1 | 174 | 0 | 1 | 174 | 0 calculate_cell_height_on_model | 1 | 75 | 0 Geo.apply_periodic_boundary_conditions | 1 | 52 | 0 | 2 | 39 | 0 | 2 | 39 | 0 | 2 | 38 | 0 | 1 | 25 | 0 | 1 | 17 | 0 get_four_fold_vertices | 2 | 10 | 0 Geo.get_substrate_z | 2 | 4 | 0 | 2 | 2 | 0 | 2 | 2 | 0 VertexModelVoronoiFromTimeImage.renumber_tets_xs | 1 | 2 | 0 Geo.compute_edge_length_0 | 2 | 1 | 0 | 1 | 1 | 0 Cell.add_noise_to_parameters | 300 | 1 | 0 Set.redirect_output | 1 | 1 | 0 | 2 | 0 | 0 | 300 | 0 | 0 VertexModelVoronoiFromTimeImage.create_temporary_folder | 1 | 0 | 0 | 7 | 0 | 0 VertexModelVoronoiFromTimeImage.__init__ | 1 | 0 | 0 VertexModelVoronoiFromTimeImage.__init__ | 1 | 0 | 0 add_noise_to_parameter | 2400 | 0 | 0 | 300 | 0 | 0 Set.update_derived_parameters | 1 | 0 | 0 | 2 | 0 | 0 | 1 | 0 | 0 | 2 | 0 | 0 | 1 | 0 | 0 | 1 | 0 | 0 | 95 | 0 | 0 Geo.compute_centre_of_tissue | 1 | 0 | 0 | 1 | 0 | 0 | 2 | 0 | 0 | 2 | 0 | 0 | 1 | 0 | 0 | 514 | 0 | 0 | 2 | 0 | 0 | 2 | 0 | 0 | 1 | 0 | 0 | 1 | 0 | 0 | 1 | 0 | 0 | 1 | 0 | 0 | 1 | 0 | 0 | 1 | 0 | 0 | 1 | 0 | 0 add_faces_and_vertices_to_x | 2 | 0 | 0 | 1 | 0 | 0 | 2 | 0 | 0 | 1 | 0 | 0 | 1 | 0 | 0 | 2 | 0 | 0 | 1 | 0 | 0 Set.__init__ | 1 | 0 | 0 | 1 | 0 | 0 | 1 | 0 | 0 | 1 | 0 | 0 | 2 | 0 | 0 VertexModel | 1 | 0 | 0 | 2 | 0 | 0 | 2 | 0 | 0 | 2 | 0 | 0 Geo | 1 | 0 | 0 Set.define_if_not_defined | 17 | 0 | 0 Cell | 1 | 0 | 0 Geo.__init__ | 3 | 0 | 0 Set | 1 | 0 | 0 VertexModelVoronoiFromTimeImage | 1 | 0 | 0 | 1 | 0 | 0 Set.wing_disc_equilibrium | 1 | 0 | 0 KgVolume | 1 | 0 | 0 KgSurfaceCellBasedAdhesion | 1 | 0 | 0 Kg | 1 | 0 | 0 Remodelling | 1 | 0 | 0 Tris | 1...<issue_description>It is taking too much. Here is the report:
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.